<?php
namespace App\Repos;

use App\Models\UserCoupon;
use Carbon\Carbon;

class UserCouponRepo
{
	public static function  getPages($where=[],$num=10)
	{	   
	  	$list = UserCoupon::select(['id','shop_id','coupon_id','end_date','created_at','is_used'])->with('coupon:id,name,valid_days,value,min_amount')->with('shop:id,name')->where($where)->paginate($num); 	  	
	  	return $list;     
	}

	/**
	 * 用户第一次登录和拍十秒送优惠券
	 */
	public static function create($data)
	{
		// 优惠券有效期 3天
		$data['end_date'] = Carbon::now()->addDays(3);
		$flag = UserCoupon::Create($data);		
		return $flag;		
	}

	public static function find($where=[])
	{
		return UserCoupon::with('coupon')
							->where($where)
							->first();
	} 

	public static function update($where,$data)
	{
		return UserCoupon::where($where)->update($data);
	}

	public static function countNum($where)
	{
		return UserCoupon::where($where)->count();
	}

	
	
	
	

	
	
	
}